import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
        System.out.println("Hello, World!");
        Class<String> clazz = String.class;   //使用class关键字，通过类名获取
        Class<?> clazz2 = Class.forName("java.lang.String");   //使用Class类静态方法forName()，通过包名.类名获取，注意返回值是Class<?>
        Class<?> clazz3 = new Cat("cat",11,23,"orange").getClass();  //通过实例对象获取
        Method[] a =clazz3.getDeclaredMethods();
        System.out.println(clazz.getName());
        System.out.println(clazz2.getName());
        System.out.println(clazz3.getName());
        Object instance=clazz3.getConstructor(String.class,int.class,int.class,String.class).newInstance("cat",11,23,"orange");
        a[0].invoke(instance);
    }
}

class Cat{
    String name;
    int age;
    int weight;
    String color;

    public Cat(String name, int age, int weight, String color){
        this.name = name;
        this.age = age;
        this.weight = weight;
        this.color = color;
    }
    public void print(){
        System.out.println("Name: " + name + " Age: " + age + " Weight: " + weight + " Color: " + color);
    }
}
